package com.sky.controller.admin;

import com.sky.entity.AdminActionLog;
import com.sky.result.Result;
import com.sky.service.AdminLogService;
import com.sky.utils.LogConvertUtil;
import com.sky.vo.LogVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/admin/logs")
@Api(tags = "管理端端-日志的相关接口")
public class LogController {

    @Autowired
    private AdminLogService logService; // 假设存在日志服务层

    /**
     * 获取操作日志列表并转换为前端格式
     */
    @GetMapping
    @ApiOperation("获取最近的操作日志")
    public Result getOperationLogs() {
        // 1. 从数据库或其他来源获取原始日志数据
        List<AdminActionLog> logs = logService.getRecentLogs();

        // 2. 转换为前端需要的格式
        List<LogVO> result = new ArrayList<>();
        for (AdminActionLog log : logs) {
            result.add(LogConvertUtil.convertToLogVO(log));
        }

        return Result.success(result);
    }
}